home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 8 / The Arsenal Files Collection #8 (Arsenal Computer) (1996).ISO / prg_casm / wsc4c10.zip / CONFIG.C < prev    next >
Text File  |  1996-09-09  |  4KB  |  149 lines

  1. /*** config.c ***/
  2.  
  3. #include "windows.h"
  4. #include "config.h"
  5. #include "wsc.h"
  6. #include "menu.h"
  7. #include "message.h"
  8. #include "wscerror.h"
  9.  
  10. extern HWND hMainWnd;
  11. extern char Temp[256];
  12. extern int  OnLineFlag;
  13.  
  14. #define TEXT_SIZE 8
  15.  
  16. static struct
  17.  {int Port;
  18.   int BaudRateCode;
  19.   int DataBits;
  20.   int ParityCode;
  21.   int StopBitsCode;
  22.  } Config = {COM1,Baud19200,8,NoParity,OneStopBit};
  23.  
  24. static char ConfigText[TEXT_SIZE+1] = "";
  25. static char StopBitList[3] = {'1','?','2'};
  26. static char ParityList[5]  = {'N','O','E','M','S'};
  27. static unsigned BaudRateValue[9] = {110,300,1200,2400,4800,9600,19200,38400,57600};
  28.  
  29. static int PortMsgID[4] = {MSG_COM1,MSG_COM2,MSG_COM3,MSG_COM4};
  30. static int BaudRateMsgID[9] = {MSG_110, MSG_300, MSG_1200, MSG_2400,
  31.                                MSG_4800,MSG_9600,MSG_19200,MSG_38400,
  32.                                MSG_57600};
  33. static int StopBitsMsgID[3] = {MSG_1_SB,0,MSG_2_SB};
  34. static int ParityMsgID[5] = {MSG_NONE,MSG_ODD,MSG_EVEN,0,0};
  35. static int DataBitsMsgID[9] = {0,0,0,0,0,0,0,MSG_7_DB,MSG_8_DB};
  36.  
  37. static char *LineText[2] = {"OFF", "ON"};
  38.  
  39. static void SetPSL(int,int,int);
  40. static int  UpdateTheChecks(int,int);
  41.  
  42. static LastPortID = MSG_COM1;
  43. static LastParityID = MSG_NONE;
  44. static LastStopBitsID = MSG_1_SB;
  45. static LastDataBitsID = MSG_8_DB;
  46. static LastBaudRateID = MSG_19200;
  47.  
  48. void SetParity(int Parity)
  49. {
  50.  SetPSL(Config.ParityCode,Config.StopBitsCode,Config.DataBits);
  51.  LastParityID = UpdateTheChecks(LastParityID,ParityMsgID[Parity]);
  52. }
  53.  
  54. void SetStopBits(int StopBits)
  55. {
  56.  SetPSL(Config.ParityCode,StopBits,Config.DataBits);
  57.  LastStopBitsID = UpdateTheChecks(LastStopBitsID,StopBitsMsgID[StopBits]);
  58. }
  59.  
  60. void SetWordLength(int DataBits)
  61. {
  62.  SetPSL(Config.ParityCode,Config.StopBitsCode,DataBits);
  63.  LastDataBitsID = UpdateTheChecks(LastDataBitsID,DataBitsMsgID[DataBits]);
  64. }
  65.  
  66. void SetPSL(int Parity,int StopBits,int DataBits)
  67. {Config.ParityCode = Parity;
  68.  Config.StopBitsCode = StopBits;
  69.  Config.DataBits = DataBits;
  70.  SetTitle();
  71.  /* end SetPSL */
  72. }
  73.  
  74. void SetBaud(int BaudCode)
  75. {int RetCode;
  76.  Config.BaudRateCode = BaudCode;
  77.  if(OnLineFlag)
  78.    {RetCode = SioBaud(Config.Port,BaudRateValue[Config.BaudRateCode%9]);
  79.     if(RetCode<0) SioError(RetCode,"SioBaud");
  80.    }
  81.  LastBaudRateID = UpdateTheChecks(LastBaudRateID,BaudRateMsgID[BaudCode]);
  82.  SetTitle();
  83. } /* end SetBaud */
  84.  
  85. void SetPort(int Port)
  86. {
  87.  Config.Port = Port;
  88.  LastPortID = UpdateTheChecks(LastPortID,PortMsgID[Port]);
  89.  SetTitle();
  90. } /* end SetPort */
  91.  
  92. int GetBaud(void)
  93. {return (Config.BaudRateCode);
  94. }
  95.  
  96. int GetParity(void)
  97. {return (Config.ParityCode);
  98. }
  99.  
  100. int GetStopBits(void)
  101. {return (Config.StopBitsCode);
  102. }
  103.  
  104. int GetWordLength(void)
  105. {return(Config.DataBits);
  106. }
  107.  
  108. int GetPort(void)
  109. {return (Config.Port);
  110. }
  111.  
  112. void SetText(LPSTR String)
  113. {lstrcpy((LPSTR)ConfigText,String);
  114. }
  115.  
  116. void SetTitle(void)
  117. {wsprintf((LPSTR)Temp,"%s: COM%d @ %u baud %d%c%c %sLINE",
  118.     (LPSTR)ConfigText,
  119.     Config.Port+1,
  120.     BaudRateValue[Config.BaudRateCode%9],
  121.     Config.DataBits,
  122.     ParityList[Config.ParityCode],
  123.     StopBitList[Config.StopBitsCode],
  124.     (LPSTR)LineText[1&OnLineFlag]);
  125.     SetWindowText(hMainWnd,(LPSTR)Temp);
  126. }
  127.  
  128. void UncheckAll(void)
  129. {UncheckTheMenu(LastPortID);
  130.  UncheckTheMenu(LastParityID);
  131.  UncheckTheMenu(LastStopBitsID);
  132.  UncheckTheMenu(LastDataBitsID);
  133.  UncheckTheMenu(LastBaudRateID);
  134. }
  135.  
  136. void CheckAll(void)
  137. {CheckTheMenu(LastPortID);
  138.  CheckTheMenu(LastParityID);
  139.  CheckTheMenu(LastStopBitsID);
  140.  CheckTheMenu(LastDataBitsID);
  141.  CheckTheMenu(LastBaudRateID);
  142. }
  143.  
  144. int UpdateTheChecks(int OldMsgID,int NewMsgID)
  145. {UncheckTheMenu(OldMsgID);
  146.  CheckTheMenu(NewMsgID);
  147.  return NewMsgID;
  148. }
  149.